//
//  ProjectCVC.swift
//  DoctorVisits
//
//  Created by lanou3g on 16/2/29.
//  Copyright © 2016年 SHH. All rights reserved.
//

import UIKit

class ProjectCVC: UIViewController,UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {

    let width = UIScreen.mainScreen().bounds.width
    let height = UIScreen.mainScreen().bounds.height
    
    override func viewDidLoad() {
        super.viewDidLoad()
     
        loadCollectionView()
    }

    func loadCollectionView() {
        
        let layout = UICollectionViewFlowLayout()
        
        layout.sectionInset = UIEdgeInsetsMake(0, self.view.frame.size.width*0.03, 5, self.view.frame.size.width*0.03)
        layout.itemSize = CGSize(width: width * 0.25, height: height * 0.18)
        
        layout.scrollDirection = .Vertical
        
        layout.minimumInteritemSpacing = 0
        
        layout.minimumLineSpacing = 10
        
        let collectionView = UICollectionView(frame: CGRectMake(0, 0, width, height),collectionViewLayout: layout)
        
        collectionView.backgroundColor = UIColor.whiteColor()
        
        //代理
        
        collectionView.delegate = self
        
        collectionView.dataSource = self
        
        //注册
        
         collectionView.registerNib(UINib(nibName: "ProjectCVCell", bundle: nil), forCellWithReuseIdentifier: "cell")
        
        collectionView.registerClass(UICollectionReusableView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier:"headView")
        
        self.view.addSubview(collectionView)
        
        
        //设置collectionView的偏移量
        collectionView.contentInset = UIEdgeInsetsMake(200,0, 0, 0)
        //设置表头视图
        let label:UILabel = UILabel(frame:CGRectMake(0,-280,width*0.5,200))
        
        label.text = "司航航"
        
        collectionView.addSubview(label)
        
        
        
        
       
        
        
    }
    
    
    
   
    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        return 1
    }
    

    
    
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 16
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! ProjectCVCell
        
        cell.imageView!.image = UIImage(named: "1.jpg")
        
        
        return cell
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
        
        let headView = collectionView.dequeueReusableSupplementaryViewOfKind(UICollectionElementKindSectionHeader, withReuseIdentifier: "headView", forIndexPath: indexPath)
        
       
        
        return headView
        
    }
    
    func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
        return CGSize(width: width, height: 5)
    }

    
    func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
        
        let PVC:ProjectVC = ProjectVC()
        
        self.navigationController?.pushViewController(PVC, animated:true)
        
        
    }
    
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
